// routes/TravelRouteRouter.ts
import express from 'express';
import { TravelRouteService } from '../../service';

const router = express.Router();

// 获取顾客旅行路线
router.get('/:customerName', async (req, res) => {
    try {
        const { customerName } = req.params;

        // 验证必填字段
        if (!customerName) {
            return res.status(400).json({
                success: false,
                message: '顾客姓名为必填项'
            });
        }

        const travelRoute = await TravelRouteService.getCustomerTravelRoute(customerName);
        
        res.json({
            success: true,
            data: travelRoute,
        });
    } catch (error: any) {
        // console.error('获取旅行路线失败:', error);
        
        if (error.message.includes('顾客不存在')) {
            res.status(409).json({
                success: false,
                message: error.message
            });
        } else if(error.message.includes('未查询到旅游路线')){
            res.status(409).json({
                success: false,
                message: error.message
            })
        }
        else {
            res.status(500).json({
                success: false,
                message: '获取旅行路线失败'
            });
        }
    }
});
export default router;